#pragma once
#include "portecol.hpp"
#include "portecol.hpp"
using namespace protecol_ns;
class calculate
{
public:
    calculate()
    {
    }
    response execute(const request &req)
    {
        response resq(0, 0);
        switch (req._oper)
        {
        case '+':
            resq._result = req._x + req._y;
            break;
        case '-':
            resq._result = req._x - req._y;
            break;
        case '*':
            resq._result = req._x * req._y;
            break;
        case '/':
        {
            if (req._y == 0)
            {
                resq._code = 1;//除零错误，返回错误码为1
            }
            else
            {
                resq._result = req._x / req._y;
            }
        }
        break;
        case '%':
            if (req._y == 0)
            {
                resq._code = 2;//%0 错误，返回错误码为2
            }
            else
            {
                resq._result = req._x % req._y;
            }
            break;

        default:
            resq._code = 3;//操作符错误，返回错误码为3
            break;
        }
        return resq;
    }
    ~calculate()
    {
    }

private:
};